<%@page language="java" import="org.apache.commons.fileupload.*, java.util.*, java.io.*, javax.servlet.ServletContext" %>
<%

ServletContext servletContext = this.getServletContext() ;
String realPathApl = servletContext.getRealPath("");



String pastaTmp= realPathApl + File.separator + "tempbib";
String pastaUp= realPathApl + File.separator + "uploadbib";

if (FileUpload.isMultipartContent(request)){

		File tempFl = new File(pastaTmp);
		File uploadFl=new File(pastaUp);
		
		if(!tempFl.exists()){
			tempFl.mkdir();
		}
		if(!uploadFl.exists()){
			uploadFl.mkdir();
		}
		
			
		DiskFileUpload upload = new DiskFileUpload();
		upload.setRepositoryPath(pastaTmp);
		
		try{
		    List items = upload.parseRequest(request);
		    Iterator iter = items.iterator();
		    
		    while (iter.hasNext()) {
		
		        FileItem item = (FileItem) iter.next();
				if (!item.isFormField()) {
		
					String nome=item.getName().toString();
					String nomeArquivo=nome.substring(nome.lastIndexOf("\\")+1);
					
					File arquivo=new File(pastaUp + File.separator + nomeArquivo);
		
					item.write(arquivo);
				}
			}
		    
		}catch(FileUploadException e){
			e.printStackTrace();
		}
}

%>